Configure Calculated Attribute: Calculation Rules

The Calculation Rules tab allows you to define the expression used to derive a value for a Calculated Attribute.

The Loyalty platform offers two methods of defining the expression: 

  • Advanced : Enter a custom Groovy expression.

  • Simple: Utilize the platform's user interface to build the underlying Groovy expression.

Note: You can optionally use both methods. For example, you can build an expression using the Simple method, then switch to the Advanced method. The code editor will display the generated Groovy expression, which you can manually modify as needed.

Advanced Method

The Advanced method allows you to manually enter a Groovy expression.

  1. Navigate to the Calculation Rules tab of the Member Attribute Details screen.

  2. Select Advanced.

  3. In the code editor, enter your Groovy expression.

  4. Click Save.

Simple Method

The Simple method is intended for non-technical users, and allows you to build Calculation Rules without having to write Groovy code. Each Calculation Rule comprises a Condition (criteria to evaluate) and a Result (value to populate when the Condition evaluates to "true").

That platform evaluates each Calculation Rule in sequence from top to bottom:

  • If a Calculation Rule evaluates to "true," the Result is applied.

  • If a Calculation Rule evaluates to "false," the next Calculation Rule is evaluated.

  • If no Calculation Rules evaluate to "true," the platform uses the Default Value defined for this Member Attribute.

This screen utilizes the term Rule in two different contexts. This article uses the following terms to differentiate between the two types of Rules:

  • Calculation Rule: A combination of a Condition and a Result as described above. A Calculated Attribute can have one or more of these types of Rules. Calculation Rules use an IF-THEN-ELSE structure. For example:

    • Evaluate Rule A

    • IF Rule A is True THEN Use Result A

    • ELSE Evaluate Rule B, etc.

  • Conditional Rule: A single logical statement used within the Condition, typically comprising a data element, an operator, and a value (for example, "Tier equal to Gold"). A Condition can have one or more of these types of Rules. Multiple Conditional Rules are joined with either an AND or an OR operator.

To define the expression for a Calculated Attribute using the Simple method:

  1. Navigate to the Calculation Rules tab of the Member Attribute Details screen.

  2. Select Simple.

  3. Click Add Rule. The platform adds a new area for defining the Calculation Rule.

  1. Define the Condition(s) for the Calculation Rule (see Define a Condition below for details).

  2. Define the Result for the Calculation Rule (see Define the Result below for details).

  3. Repeat the above steps as necessary to add additional Calculation Rules.

  4. Optionally, to rearrange the sequence of Calculation Rules, click-and-drag the handle in the top-left corner of the Calculation Rule box, and drop it in its desired new location.

  5. Optionally, to delete a Calculation Rule, click the Delete link next to it.

  6. Click Save.

  7. As you define a Calculation Rule, the platform automatically generates the Groovy expression for it. To see the underlying expression for a Calculation Rule, click the Show Expression link next to it.

Note: You can also view the underlying Groovy expression for the entire Calculated Attribute (comprising all Calculation Rules) by clicking the Show Expression button.

Define a Condition

A Condition is a set of logical criteria that the platform evaluates for a Member when the Calculated Attribute is refreshed. The default Condition for a new Calculation Rule is "Always True," meaning there are no criteria to evaluate.

To define a Condition:

  1. Click the Edit icon next to Always True.

  1. Click the Add icon, then select Add Rule. The platform adds a new blank row. 

  1. The first drop-down menu is populated with all of the different object types in Loyalty that are available for use. From this drop-down menu, select one of the following object types to expand it and see the available options:

 

  1. Repeat the above steps as needed to define more Conditional Rules.

  2. Optionally, to remove a Conditional Rule, click the Remove icon next to it.

  3. Once you define more than one Conditional Rule, select the logical operator. From the Include customers that meet drop-down menu, select either: 

    • All of the following: Use an 'AND' operator such that all Conditional Rules must be true for the Calculation Rule to evaluate to "true."

    • Some of the following: Use an 'OR' operator such that at least one of the Conditional Rules must be true for the Calculation Rule to evaluate to "true." 

  4. Optionally, you can also organize Conditional Rules into Rule Groups. A Rule Group allows you to build more complex logical criteria. To create a Rule Group, click the Add icon, then select Add Rule Group. The platform creates a Group, which is represented visually as a nested box with its own operator and Add icon. Within this Group box, click the Add icon to define the Conditional Rule (or Rules) using the same process as described above. Use the toggle within the Group box to define the logical operator.

Note: By clicking the Group button inside the Group box, you can create "nested" groups.

  1. Click Save.

Define the Result

When a Condition evaluates to true for a Member, the Result determines the value assigned to the Calculated Attribute. The platform provides the following options for defining the Result: